//
//  MKWorkRecommendCell.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/11.
//  Copyright © 2017年 cc.moko. All rights reserved.
//  作品推荐cell

import UIKit

class MKWorkRecommendCell: MKBaseTableViewCell {

    var workOne:MKWorkRecommendButton!
    var workTwo:MKWorkRecommendButton!
    var workThree:MKWorkRecommendButton!
    var workFour:MKWorkRecommendButton!
    var workFive:MKWorkRecommendButton!
    var workSix:MKWorkRecommendButton!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.backgroundColor = UIColor.randomColor()
        
        self.workOne = MKWorkRecommendButton()
        self.contentView.addSubview(self.workOne)
        
        self.workTwo = MKWorkRecommendButton()
        self.contentView.addSubview(self.workTwo)
        
        self.workThree = MKWorkRecommendButton()
        self.contentView.addSubview(self.workThree)
        
        self.workFour = MKWorkRecommendButton()
        self.contentView.addSubview(self.workFour)
        
        self.workFive = MKWorkRecommendButton()
        self.contentView.addSubview(self.workFive)
        
        self.workSix = MKWorkRecommendButton()
        self.contentView.addSubview(self.workSix)
        }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let width:CGFloat = (ScreenWidth - 10) / 3
        let height:CGFloat = width * 260 / 244

        self.workOne.frame = CGRect.init(x: 0, y: height + 5 + 8, width: width * 2 + 5, height: height * 2 + 5)
        self.workTwo.frame = CGRect.init(x: 0, y: 8, width: width, height: height)
        self.workThree.frame = CGRect.init(x: self.workTwo.right + 5, y: 8, width: width, height: height)
        self.workFour.frame = CGRect.init(x: self.workThree.right + 5, y: 8, width: width, height: height)
        
        self.workFive.frame = CGRect.init(x: self.workThree.right + 5, y: self.workFour.bottom + 5, width: width, height: height)
        self.workSix.frame = CGRect.init(x: self.workThree.right + 5, y: self.workFive.bottom + 5, width: width, height: height)

    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

class MKWorkRecommendButton: UIButton {
    
    var icon:UIImageView!
    var name:UILabel!
    var tip:UILabel!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.randomColor()

        self.icon = UIImageView.init()
        self.icon.image = UIImage.init(named: "newHome_hotActor_bottomBlack")
        self.addSubview(self.icon)
        
        self.name = UILabel.label(fontSize: 14, textColor: UIColor.white)
        self.name.text = "谁说遥远太遥远"
        self.addSubview(self.name)
        
        self.tip = UILabel.label(fontSize: 11, textColor: UIColor.white)
        self.tip.text = "嘻哈风格"
        self.addSubview(self.tip)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.icon.frame = self.bounds
        self.name.sizeToFit()
        self.tip.sizeToFit()
        self.tip.frame = CGRect.init(x: 15, y: self.height - 5 - self.tip.height, width: self.width - 10, height: self.tip.height)
        self.name.frame = CGRect.init(x: 10, y: self.tip.top - 5 - self.name.height, width: self.width - 10, height: self.name.height)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
